package cn.concurrence.juc;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * 	公司下班
 *
 *	所有员工都走了，才能关门
 *
 * @author summit
 * @since 2022/4/24 14:32
 */
public class CountdownLatchTest {

	public static void main(String[] args) throws InterruptedException {
		CountDownLatch cdl = new CountDownLatch(3);

		for (int i = 0; i < 3; i++) {
			new Thread(() -> {
				// -1
				cdl.countDown();

				try {
					TimeUnit.SECONDS.sleep(2);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}).start();
		}

		// 等待cdl的值为0 才能继续往下走
		cdl.await();

		System.out.println("全都结束==========");
	}
}
